package com.ncloud.crm.service.impl;


import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.ncloud.crm.entity.Logistics;
import com.ncloud.crm.mapper.LogisticsInfoMapper;
import com.ncloud.crm.service.LogisticsServer;
import com.ncloud.param.service.SequenceService;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by shiqiang on 2017/7/5.
 */
@Service
public class LogisticsServerImpl implements LogisticsServer{
    private static final Logger logger = LogManager.getLogger(LogisticsServerImpl.class);
    @Autowired
    private LogisticsInfoMapper logisticsInfoMapper;
    @Reference
    private SequenceService sequenceService;
    @Override
    public int insertLogistics(Logistics logistics) {
        if(logistics.getLogisticsId() == null){
            Long id = sequenceService.getSequence("Logistics_seq");
            logistics.setLogisticsId(id);
        }
        logistics.setCreateTime(new Date());
        return logisticsInfoMapper.insertLogistics(logistics);
    }

    @Override
    public JSONObject getLogisticsMailInfo(Long workId, Long nodeId) {
        return logisticsInfoMapper.getLogisticsMailInfo(workId,nodeId);
    }

    @Override
    public Logistics getLogisticsInfoByNode(Long workId, Long nodeId) {
        return logisticsInfoMapper.getLogistics(workId,nodeId);
    }
}
